package com.example.demo.test3;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest {
    public static void main(String[] args) {
//        ExecutorService es = Executors.newFixedThreadPool(4);
//        es.submit(new MyThreadImpl());
//        ScheduledExecutorService es = Executors.newScheduledThreadPool(4);
//        es.scheduleAtFixedRate(new MyThreadImpl(), 1,3, TimeUnit.SECONDS);

        //创建可缓存线程池对象
        ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
        //创建Runnable类线程对象 & 需执行任务
        Runnable task = new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "执行任务了");
            }
        };
        //向线程池提交任务
        for (int i = 0; i < 5; i++) {
            cachedThreadPool.execute(task);
        }

    }
}
